/**
@author		Jong Min, Lee
@date		  02/06/2014
@breif		toolbox stack control

copyright(c) Tae Young Soft. All right reserved. 2014
*/
#pragma once

#include <list>
#include "Taurus_Common/Monitor.h"
#include "TAURUS_CTRL/EXButton.h"
#include "Taurus_Viewer/Toolbox.h"

class CToolboxData;

/**
@brief  toolbox stack control
*/
class CToolboxStack : public CWnd
{
	DECLARE_DYNAMIC(CToolboxStack)

public:
  typedef struct tagCreateParams
  {
    MonitorResolutionType enumResType;
  }CreateParams;

public:
  /**
  @brief		default constructor
  */
	CToolboxStack();

  /**
  @brief		destructor
  */
	virtual ~CToolboxStack();

  /**
  @brief		open toolbox data
  @param		arrToolboxData pointer to array of toolbox data to be open
  @param    nNumToolboxData the number of toolbox data to be open
  @param    bRedraw flag indicating whether toolbox stack is to be redrawn
  @return		ERROR_SUCCESS if succeeds, an error code otherwise
  */
  DWORD openToolboxes(const CToolboxData** arrToolboxData,
                      const unsigned nNumToolboxData,
                      BOOL bRedraw);

private:

  typedef struct tagToolboxStackItem
  {
    CToolbox wndToolbox;

    CButton btnTitle;

    CString strToolboxName;

    BOOL bOpen;
  }CToolboxStackItem;

private:
  /**
  @brief		request a toolbox stack item to open a toolbox
  @param		pToolboxStackItem pointer to toolbox stack item to be request
  @param    pToolboxData pointer to toolbox data to be open
  @return		ERROR_SUCCESS upon success, an error code otherwise
  */
  DWORD openToolbox(CToolboxStackItem& cToolboxStackItem,
                    const CToolboxData& cToolbox);

  /**
  @brief		open a toolbox stack item
  @param		index the number of toolbox stack item to be open
  */
  void openToolboxStackItem(const unsigned index);

  /**
  @brief		open a toolbox stack items vertically
  */
  void openToolboxStackItemV();

  /**
  @brief		open a toolbox stack items horizontally
  */
  void openToolboxStackItemH();

  /**
  @brief		create th toolbox stack item control and attach it toolbox stack item
  @param		cToolboxStackItem toolbox stack item
  @param    uItemID toolbox stack item ID
  @return		ERROR_SUCCESS if succeeds, an error code otherwise
  */
  DWORD createToolboxStackItem(CToolboxStackItem& cToolboxStackItem,
                               UINT uItemID);

  /**
  @brief		rearrange toolbox stack items
  @param		bRedraw flag indicating whether toolbox stack items are to be redrawn
  */
  void rearrangeStackItems(BOOL bRedraw);

  /**
  @brief		rearrange toolbox stack items vertically
  @param		bRdraw flag indicating whether toolbox stack items are to be redrawn
  */
  void rearrangeStackItemsV(BOOL bRedraw);

  /**
  @brief		rearrange toolbox stack items horizontally 
  @param		bRdraw flag indicating whether toolbox stack items are to be redrawn
  */
  void rearrangeStackItemsH(BOOL bRedraw);

  /**
  @brief		get title button size
  @param		enumResType monitor resolution type
  @param    bVertical flag indicating whether title button is vertical or horizontal
  @return		title button size
  */
  CSize getTitleButtonSize(MonitorResolutionType enumResType,
                           BOOL bVertical) const;

  /**
  @brief		get title button margin
  @param		enumResType monitor resolution type
  @param    bVertical flag indicating whether title button is vertial or horizontal
  @return		title button margin
  */
  CSize getTitleButtonMargin(MonitorResolutionType enumResType, BOOL bVertical) const;

  /**
  @brief		destroy the toolbox stack item control and detach from toolbox stack item
  */
  void  destroyStackItem(CToolboxStackItem& cItem);

  /**
  @brief		destroy the toolbox stack item controls and detach from toolbox stack items
  */
  void destroyAllStackItems();

  /**
  @brief		remove all toolbox stack items
  */
  void removeAllStackItems();

  /**
  @brief		check whether createparams is legal
  @param		stParams create params to be checked
  @return		TRUE if legal, FALSE otherwise
  */
  BOOL validateCreateParams(const CreateParams& stParams);

private:

  //monitor resolution type
  MonitorResolutionType m_enumResType;

  //toolbox stack items
  std::list<CToolboxStackItem*> m_listItems;

protected:
	DECLARE_MESSAGE_MAP()
  
  afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
  afx_msg void OnSize(UINT nType, int cx, int cy);
  afx_msg void OnPaint();
  afx_msg BOOL OnEraseBkgnd(CDC* pDC);
  afx_msg void OnDestroy();

  virtual BOOL OnCommand(WPARAM wParam, LPARAM lParam);
};